#include "key.h"


#define KEY_UNPRESS 0

GPIO_PinState key1_value()
{
    return HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin);
}

/**
 * @brief   检测按键,查看哪个按键被按下，并完成消抖
 * 
 * @param   mode: 0-不支持连续扫描  1-支持连续扫描
 * @return  按键值
 */
uint8_t key_scan(uint8_t mode)
{
    static uint8_t key_value = 0;
    uint8_t old_key = key_value;

    if(key1_value()==0)
    {
        HAL_Delay(10);

        if(key1_value()==0)
        {
            key_value = 1;
        }
    }
    else
    {
        key_value = KEY_UNPRESS;
    }
    if(mode == 0&& old_key==key_value)
        return KEY_UNPRESS;
    return key_value;
}